package com.baibei.ebec.welcome;

import android.app.AlertDialog;
import android.app.Dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;

import com.baibei.crossboarder.R;
import com.baibei.model.ProductInfo;
import com.baibei.module.ViewUtil;
import com.baibei.module.stock.simple.SimpleStockFragment;
import com.blankj.utilcode.utils.LogUtils;
import com.blankj.utilcode.utils.ScreenUtils;

/**
 * Created by tang on 2018/8/8.
 */

public class PriceFlowDialog extends DialogFragment implements View.OnClickListener {

    private FrameLayout fralChart;
    private ProductInfo pInfo;

    public static PriceFlowDialog getInstance(ProductInfo pInfo){
        PriceFlowDialog priceFlowDialog = new PriceFlowDialog();
        Bundle bundle = new Bundle();
        bundle.putParcelable("pInfo",pInfo);
        priceFlowDialog.setArguments(bundle);
        return priceFlowDialog;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        pInfo = bundle.getParcelable("pInfo");
        this.setCancelable(false);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.item_pop_guide, container, false);
        Window window = getDialog().getWindow();
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        window.setLayout(-1, -2);

        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.gravity = Gravity.BOTTOM;
        window.setAttributes(attributes);
        return view;
    }


    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        view.findViewById(R.id.iv_close).setOnClickListener(this);
        fralChart = view.findViewById(R.id.fral_chart);
        ViewUtil.setViewSize(fralChart, ScreenUtils.getScreenWidth(), (int) (ScreenUtils.getScreenWidth() * 0.9));
        getChildFragmentManager().beginTransaction().replace(R.id.fral_chart, SimpleStockFragment.newInstance(pInfo.getProductId())
                ,"stock").commit();
    }

    @Override
    public void onClick(View view) {
        dismiss();
    }
}
